﻿#region Creditos

/* Autor: Edilberto Sánchez Forero	*/
/* Email: esanchezfo@gmail.com		*/
/* Licencia: Propietario			*/
/* País: Colombia, Bogotá			*/

#endregion

#region Librerias

using System.Runtime.Serialization;
using System;
using ESF.General.Entity;

#endregion


namespace ESF.General.Entity
{
	[DataContract]
	[Serializable]
	public class UserMenuItem : BasicReference, IEquatable<UserMenuItem>
	{
		[DataMember]
		public string URL { set; get; }

		
		[DataMember] 
		public UserMenuItem Parent { set; get; }


		[DataMember]
		public BasicReference Application { set; get; }


		public bool calMarked { set; get; }


		#region Propiedades de solo lectura

		public int? ParentID { get { return (Parent == null ? null : Parent.ID); } }
		public string ParentCode { get { return (Parent == null ? null : Parent.Code); } }

		public int? ApplicationID { get { return (Application == null ? null : Application.ID); } }
		public string ApplicationCode { get { return (Application == null ? null : Application.Code); } }

		#endregion
		

		#region Miembros de IEquatable<UserMenuItem>

		public override int GetHashCode()
		{
			if (ID != null) { return ID.GetHashCode (); }
			
			if (Code != null) { return Code.GetHashCode (); }
			
			return 0;
		}
		

		public override bool Equals (object pObj)
		{
			if (pObj is UserMenuItem)
			{
				return Equals (pObj as UserMenuItem);
			}
		
			return false;
		}
		

		public bool Equals (UserMenuItem pOther)
		{
			if (pOther == null) { return false; }
		
			if (ID != null)
			{
				return (pOther.ID == ID);
			}
		
			if (Code != null)
			{
				return (pOther.Code == Code);
			}
			
			return false;
		}

		#endregion
	}
}
